/**
 * 工具类， 暴露全局$F对象
 */
(function ($) {
    function getNowData() {
        var now = new Date(), seconds = now.getSeconds(), minutes = now.getMinutes();
        if (parseInt(seconds) < 10) seconds = '0' + now.getSeconds();
        if (parseInt(minutes) < 10) minutes = '0' + now.getMinutes();
        return now.getHours() + ":" + minutes + ":" + seconds;
    }

    $F = {
        showConfirm: function (msg, confirmFunc, cancelFunc) {
            var confirmContainer = $('.confirm-container');
            if (confirmContainer.length > 0) {
                $('.confirm-container .msg').html(msg);
                confirmContainer.show();
                $('.bg_cover').show();
            } else {
                var hei = $("html").height();
                var wid = $("html").width();
                var mheight = (hei - 150) / 2;
                var mwidth = (wid - 300) / 2;

                confirmContainer = $('<div class="confirm-container"><div class="msg">' + msg +
                    '</div><div class="btn-container"><a class="confirm-btn">' + i18n.page.endChatConfirmBtn + '</a><a class="cancel-btn">' + i18n.page.endChatCancelBtn + '</a></div></div>').css({
                        "left": mwidth,
                        "top": mheight
                    });
                $("body").append(confirmContainer);

                $('.confirm-container .confirm-btn').on('click', function () {
                    UI.rateClientShut();
                    $('.confirm-container').hide();
					//$F.appendTextToDiv("clientResponseDiv", $F.formatNotice(i18n.page.chattingOver));
                    //读取配置文件是否弹出满意度
                    if ($.isFunction(confirmFunc)) {
                        confirmFunc();
                    }
                });

                $('.confirm-container .cancel-btn').on('click', function () {
                    $('.confirm-container').hide();
                    $('.bg_cover').hide();
                    if ($.isFunction(cancelFunc)) {
                        cancelFunc();
                    }
                });
                $('.bg_cover').show();
            }
        },
        getCancelRequestJSON: function () {
            var cancelRequestJSON = {
                actionType: "cancelRequest",
                chatRequestId: _chatRequestId
            };
            return JSON.stringify(cancelRequestJSON);
        },
        giveUpChat: function () {
            if (confirm($config.confirmRequestCancelMessage)) {
                $F.doAjaxCall(Constants.ajaxURL, "requestType=send&data=" + $F.getCancelRequestJSON());
                _sessionActive = false;
                $F.formatAndShowNotice($config.requestCancelledMessage, false);
            }
            $("#leaveMsg_div").click();
        },
        showATag: function (url, name) {
            window.open(url, name, "height=800, menubar=no,toolbar=no,titlebar=no,status=no");
        },
        openATag: function (type, url, name, classA, styleA) {
            if (!type) type = 0;
            if (type == 0) {
                return '<a class="' + classA + '" href="' + url + '"  class="' + styleA + '" target="_blank">' + name + '</a>';
            }
            else if (type == 1) {
                result = '<a class="' + classA + '" href="###"  class="' + styleA + '" onclick="$F.showATag(\'' + url + '\', \'' + name + '\');">' + name + '</a>';
                return result;
            } else {
                return null;
            }
        },
        getSessionRatingJSON: function (ratingId, comments, extendInfo) {
            var r = {
                clientId: Constants.client.clientId,
                chatSessionId: $config.thisSessionId,
                ratingId: ratingId,
                ratingComment: comments,
                ratingExtendVOList: extendInfo
            };
            return JSON.stringify(r);
        },
        getRatingExtendInfoJSON: function (ratingId, ratingExtendId, ratingExtendType, ratingExtendValue) {
            var r = {
                chatSessionId: $config.sessionId,
                ratingId: ratingId,
                ratingExtendId: ratingExtendId,
                ratingExtendType: ratingExtendType,
                ratingExtendValue: ratingExtendValue
            };
            return JSON.stringify(r);
        },
        rateAfter: function (str) {
            clearShowRatingTimer();
            if (Constants.rate.rateSender == Constants.rate.rateType.CLIENT_CLOSE) {
                if (Constants.rate.client.rateOrEnd == Constants.rate.openRate.AFTER_CLOSE) {
                    if (_sessionActive) {
                        var closeSessionJSON = {
                            actionType: "closeSession",
                            senderId: Constants.client.clientId,
                            senderName: Constants.client.clientName,
                            sessionId: $config.sessionId,
                            closeType: Constants.CloseType.CLIENT_CLOSE
                        };
                        $F.doAjaxCall(Constants.ajaxURL, {
                            requestType: 'send',
                            data: JSON.stringify(closeSessionJSON)
                        });
                        $config.chatTime = 0;
                        $("#time").html("没有活动");
                        _sessionActive = false;
                        $config.sessionId = -1;
                        UI.doEnd();
                    }
                }
                if ($config.queue.endUrl) {
                    if (!_sessionActive) {
                        window.location = $config.queue.endUrl;
                    }
                } else {
                    if (config && config.page && config.page.endTurnPage && !Constants.OpenRate.hasRating) {
                        if ($config.queue.endUrl || config.page || config.page.endUrl) {
                            setTimeout(function () {
                                window.location = $config.queue.endUrl || config.page.endUrl;
                            }, 2000);
                        }
                    }
                }

            }
            if (typeof(aterRatePage) != 'undefined' && $.isFunction(aterRatePage))
                aterRatePage();
        },
        /**
         * 判断一个文件名后缀是不是属于图片类型
         * @param fileName
         */
        isImage: function (fileName) {
            if (fileName.lastIndexOf('.') > -1) {
                fileName = fileName.substring(fileName.lastIndexOf('.') + 1);
            }
            var exts = ['PNG', 'JPG', 'JPEN', 'BMP'];
            for (var i = 0; i < exts.length; i++) {
                var ext = exts[i];
                if (this.equalsIgnoreCase(fileName, ext)) {
                    return true;
                }
            }
            return false;
        },
        /**
         * 忽略大小写进行比较
         * @param s {string} 比较源
         * @param t {string} 比较目标
         * @return {boolean}
         */
        equalsIgnoreCase: function (s, t) {
            if (this.isEmpty(s) && this.isEmpty(t)) {
                return true;
            }
            if (!this.isEmpty(s) && !this.isEmpty(t) && s.toLowerCase() == t.toLowerCase()) {
                return true;
            }
            return false;
        },
        /**
         * 判断某个对象是否为undefined或者null或者空字符串
         * @method isEmpty
         * @param {string} object 对象
         * @return {boolean}
         */
        isEmpty: function (e) {
            return (e == undefined || e == null || (typeof (e) == "string" && $.trim(e) == ""));
        },
        /**
         * 过滤字符中url，用a标签包装识别出来的url。只会包装dom元素的text内容，而不会去包装dom的属性中的url
         */
        wrapURL: function (str) {
            try {
                if ($(str).length > 0) {
                    return str;
                }
            } catch (e) {
            }
            // 原来的正则必须包含http://或者https://     /(http:|https:)\/\/[A-Za-z0-9\._\?%&+\-=/#]*/gi
            var matchURLs = $('<div>').append(str).text().match(/(((https?:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www\..|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)(?::(\d+))?((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\+~%\/.\w-_\?=&;%@]*))?)/g);
            if ($.isArray(matchURLs)) {
                $.unique(matchURLs);
            }
            if (matchURLs) {
                $.each(matchURLs, function (i, url) {
                    //经过text()方法后，字符串中的&amp;会变成& 这里要判断一下，如果存在这种情况，就要再replace一次
                    var parsedUrl = url.replace(/&/g, '&amp;');
                    str = str.replaceAll(parsedUrl, function (matchStr) {
                        var url = matchStr;
                        if (!matchStr.startWith('http://') && !matchStr.startWith('https://')) {
                            url = 'http://' + matchStr;
                        }
                        return '<a target="_blank" href="' + url + '">' + matchStr + '</a>';
                    });
                });
            }
            return str;
        },
        /**
         * 返回扩展信息内容
         * @returns {*}
         */
        appendTextToDiv: function (divId, data) {
            var container = $('<div>').append(data);
            $("img:not(.emot, .avatar)", container).each(function (i, img) {
                var imgObj = $(img);
                imgObj.css("max-width", "300px").css("max-height", "300px").css("cursor", "pointer").on("load", function () {
                    $COMM.autoResizeImage(300, 300, this);
                    scrollToBottom();
                });
                var tagUrl = imgObj.attr('src');
                if (tagUrl.startsWith(' image/png')) {
                    imgObj.attr('src', tagUrl.replace(' image/png','data:image/png'));
                }
            });

            $("#" + divId).append(container.html());
            $('.lele .avatar').on('error', function () {
                $(this).prop('src', 'jsp/standard/theme/' + $config.theme + '/img/agent.jpg');
            });

            $('.me .avatar').on('error', function () {
                $(this).prop('src', 'jsp/standard/theme/' + $config.theme + '/img/client.jpg');
            });
            $("img:not(.emot, .avatar)", $("#" + divId)).each(function (i, img) {
                var imgObj = $(img);
                imgObj.off("click").on("click", function () {
                    $COMM.showOriginImage(this);
                });
            });
            scrollToBottom();
        },

        prependTextToDiv: function (divId, data) {
            var startHeight = $('#clientResponseDiv').height();
            var container = $('<div>').append(data);
            container.find("img:not(.emot, .tb-img)").each(function (i, img) {
                var imgObj = $(img);
                imgObj.css("max-width", "300px").css("max-height", "300px").css("cursor", "pointer").on("load", function () {
                    $COMM.autoResizeImage(300, 300, this);
                });
            });
            $("#" + divId).prepend(container.html());
            scrollToNum($('#clientResponseDiv').height() - startHeight + 20 + $(".button-load-talk").height());
            $("#" + divId).find("img:not(.emot, .tb-img)").each(function (i, img) {
                var imgObj = $(img);
                imgObj.off("click").on("click", function () {
                    $COMM.showOriginImage(this);
                });
            });
            $('.lele .avatar').on('error', function () {
                $(this).prop('src', 'jsp/standard/theme/' + $config.theme + '/img/agent.jpg');
            });

            $('.me .avatar').on('error', function () {
                $(this).prop('src', 'jsp/standard/theme/' + $config.theme + '/img/client.jpg');
            });
            $("img:not(.emot, .avatar)", $("#" + divId)).each(function (i, img) {
                var imgObj = $(img);
                imgObj.off("click").on("click", function () {
                    $COMM.showOriginImage(this);
                });
            });
        },
        

        formatAndShowNotice: function (msg, top, type) {
        	if (msg) {
                $('.inqueue-notice').parent().remove();
                $('.inqueue-notice').parent().prepend("br").remove();
                $('.transfer-message-tips').parent().remove();
                var tips = '';
                if (type == Constants.formatNoticeType.QUEUE) { // 队列排队消息 添加queue class 
                    tips = msg;
                }
                else if (type == Constants.formatNoticeType.OUTTIME) { // 队列排队消息 添加queue class
                    $('.inqueue-load').parent().remove();
                    $('.outtime-notice').remove();
                    tips =  "<div class=\"no-bg no-yel outtime-notice\"><div class=\"notice\">" + msg + "</div></div>";
                }
                else {
                    $('.inqueue-load').parent().remove();
                    tips =  "<div class=\"no-bg no-yel\"><div class=\"notice\">" + msg + "</div></div>";
                }
                
                if (type == Constants.formatNoticeType.QUEUE) { 
                    $F.formatNotice(tips);
                } else {
                    if (top) {
                        $F.log("显示再提示栏上" + tips);
                        $("#notice-bar").html(tips);
                    } else {
                        $F.log("显示在消息框里面" + tips);
                        $F.formatNotice(tips);
                    }
                }
        	}
        },
        formatNotice: function(msg, pre) {
            if (pre) {
                $F.prependTextToDiv("clientResponseDiv", msg);
            } else {
                $F.appendTextToDiv("clientResponseDiv", msg);
            }

        },
        /**
         * 返回浏览器类型
         * @returns {*}
         */
        getBrowserType: function () {
            return currentBrowserType;
        },
        formatFeedbackMessage: function (msg) {
            return "<div class='no-bg no-green'><font color='#808080'>" + msg + "</font></div>";
        },
        /**
         * 处理时间戳
         */
        getLocalTime: function (nS) {
            return new Date(nS).toLocaleString().replace(/年|月/g, "-").replace(/日/g, " ");
        },
        getDisplayMessage: function (preMsgUserId, userId, name, msg, posttime, icon) {
            icon = $COMM.getUserIcon(userId, icon, {
                "clientIcon": Constants.client.iconUrl,
                "robotIcon": Constants.robot.iconUrl,
                "agentIcon": Constants.agent.iconUrl,
                "queueId": $config.queueId
            });
            var result = "", msgId = -1, msgText = msg;
            if (typeof msg === 'object') {
            	msgId = msg.id;
            	msgText = msg.text;
            }
            
            if (userId == "-1") {
                result = $F.formatNotice(msgText);
            } else {
                var time = getNowData();
                if (posttime) {
                    time = $F.getLocalTime(posttime);
                }

                msgText = $EMOTION.filterEmojis(msgText);//解析表情
                if (userId == $config.client.clientId) {
                    result = '<dl class="message clearfix me">' +
                        '<div class="nowtime me-time"><span class="me-name">' + (Constants.client.clientFirstName || '访客') + '</span><span>' + time + '</span></div>' +
                        '<dt><img class="avatar" src="' + icon + '" alt="' + Constants.client.iconAlt + '" /><i class="icon"></i></dt>' +
                        '<dd><pre>' + msgText + '</pre></dd>' +
                        '</dl>';
                } else {
                    config.common.clientTimeInit = 0;
                    var agentName = name || Constants.agent.name || '人工客服';
                    var iconAlt = Constants.agent.iconAlt;
                    if ($ROBOT.isRobot(userId)) {
                        agentName = name || Constants.robot.name || '机器人';
                        iconAlt = Constants.robot.iconAlt;
                    }

                    result = '<dl class="message clearfix lele" data-id="' + msgId + '">'
                        + '<div class="nowtime lele-time">'
                        + '<span class="me-name">' + agentName + '</span><span>' + time + '</span>'
                        + '</div>'
                        + '<dt><img class="avatar" src="' + icon + '" alt="' + iconAlt + '" /><i class="icon"></i></dt>'
                        + '<dd><pre>' + msgText + '</pre></dd>' +
                        '</dl>';
                }
            }
            return result;
        },
        /**
         * 跑马灯信息提示
         */
        loadingMarquee: function (data) {
        	if (data) {
                var marquee = '';
                $.each(data, function (i, item) {
                    marquee += '<li><a href="' + item.url + '" target="_blank"> 	' + item.name + '</a> ' + item.time + '</li> ';
                })
                $("#marquee").append(marquee);
                $("#marquee").marquee({
                    yScroll: "top"        // 初始滚动方向 (还可以是"top" 或 "bottom")
                    , showSpeed: 850        // 初始下拉速度
                    , scrollSpeed: 12       // 滚动速度
                    , pauseSpeed: 5000      // 滚动完到下一条的间隔时间
                    , pauseOnHover: true    // 鼠标滑向文字时是否停止滚动
                    , loop: -1              // 设置循环滚动次数 （-1为无限循环）
                    , fxEasingShow: "swing"  // 缓冲效果
                    , fxEasingScroll: "linear"  // 缓冲效果
                    , cssShowing: "marquee-showing"  //定义class

                    // event handlers
                    , init: null               // 初始调用函数
                    , beforeshow: null           // 滚动前回调函数
                    , show: null                 // 当新的滚动内容显示时回调函数
                    , aftershow: null
                })
            }
        },
        /**
         * 轮播图片显示
         */
        loadingMargueeImg: function (margueeImgObj) {
            if (margueeImgObj) {
                var margueeImg = '';
                var carousel = '';
                $.each(margueeImgObj, function (i, item) {
                    margueeImg += ' <li class="ad"><a href="' + item.url + '"  target="_blank"><img src="' + item.imgUrl + '"></a></li>';
                    if (i == 0) {
                        carousel += '<li style="background:#fff"></li>';
                    } else {
                        carousel += '<li></li>';
                    }
                });
                $(".adbox").append(margueeImg);
                $(".btnbox").append(carousel);
                $(".adbox").width(100 * parseInt(margueeImgObj.length) + '%');
                $(".btnbox").width(24 * parseInt(margueeImgObj.length));
                $(".ad").width(100 / parseInt(margueeImgObj.length) + '%');
            }
            $F.initMargueeImg();
        },
        initMargueeImg: function () {
            var win = $(".carousel");
            var width = win.width();
            var num = 0;
            var t = setInterval(move, 5000);

            function move() {
                num++;
                if (num == $(".btnbox li").length) {
                    num = 0;
                }
                $(".btnbox li").css("background", "#ccc").eq(num).css("background", "#fff");
                $(".adbox").animate({ marginLeft: -width * num });
            }

            win.hover(function () {
                clearInterval(t)
                $(".lt").css("display", "block");
                $(".rt").css("display", "block");
            }, function () {
                t = setInterval(move, 3000)
                $(".lt").css("display", "none");
                $(".rt").css("display", "none");
            })
            $(".btnbox li").hover(function () {
                $(".adbox").finish();
                var index = $(".btnbox li").index(this)
                num = index;
                $(".btnbox li").css("background", "#ccc").eq(num).css("background", "#fff");
                $(".adbox").animate({ marginLeft: -width * num });
            })
            $(".lt").click(function () {
                $(".adbox").finish();
                num -= 2;
                if (num < -1) {
                    num = 3
                }
                move();
            })

            $(".rt").click(function () {
                $(".adbox").finish();
                move()
            })
        },
        getPostMessageSentInfoJSON: function (msg, actionType) {
            var sentInfo = {
                senderId: $config.client.clientId,
                actionType: actionType || "postMessage",
                sessionId: $config.sessionId,
                message: msg
            };
            return JSON.stringify(sentInfo);
        },
        /**
         * 加载队列数据
         */
        loadingQuee: function (queueObj, callback) {
            if (queueObj) {
                var queueArr = new Array();
                var arr = queueObj.arr;
                if (arr) {
                    var queueHtml = '<div class="queue" ><em>' + i18n.common.queueWelcome + '</em><br><lu>';
                    for (var i = 0; i < arr.length; i++) {
                        queueHtml += '<li queue="' + arr[i].queueId + '"><em>' + arr[i].name + '</em></li>';
                        queueArr.push(arr[i].queueId);
                    }
                    queueHtml += '</lu></div>';
                    $F.appendTextToDiv("clientResponseDiv", $F.getDisplayMessageRobot(queueHtml));
                    callback();
                    return queueArr;
                }

            }

        },
        /**
         * 加载头部的链接
         */
        loadingHeadLink: function (headLinkObj) {
            if (headLinkObj && headLinkObj.length > 0) {
                var htmlHeadLink = '<ul class="item-list">';
                for (var i = 0; i < headLinkObj.length; i++) {
                    var obj = headLinkObj[i];
                    htmlHeadLink += '<li><a href="' + obj.hrefLink + '" target="_blank"><img src="' + obj.imgLink + '" alt="' + obj.title + '"/>';
                    if (obj.title)
                        htmlHeadLink += '<span>' + obj.title + '</span>';
                    htmlHeadLink += '</a></li>';
                }
                htmlHeadLink += '</ul>';
                $('#navBox').html(htmlHeadLink);
                $(".tool-link").html(htmlHeadLink);
            }
        },

        loadingQuestLink: function () {
            var isShow = false;
            $.ajax({
                url: Constants.ajaxURL,
                data: {
                    requestType: 'getCommonQuestions',
                    queue: $config.queueId,
            		from: _from
                },
                method: 'POST',
                cache: false,
                error: function (jqXHR, textStatus, errorThrow) {
                    $F.log("Ajax error: " + errorThrow + "  xhr status:" + jqXHR.status + " responseText: " + jqXHR.responseText);
                },
                success: function (response) {
                    if (response.status == 'success') {
                        var data = response.commonQuestions[0];
                        if (data && data.length > 0) {
                            var htmlQuesLink = '';
                            $.each(data, function (i, item) {
                                if (parseInt(item.FLAG) == 1) {
                                    if (!isShow) {
                                        htmlQuesLink += '<div><dl class="clearfix"><dd><div class="questions"><p>常见问题</p><ul>';
                                        isShow = true;
                                    }
                                    if (item.REW_URL) {
                                        htmlQuesLink += '<li><a href="' + item.REW_URL + '" target="_blank">' + item.TITLE + '</a></li>'
                                    } else {
                                        htmlQuesLink += '<li><a href="###" data="' + item.QUESTIONS_DESC + '">' + item.TITLE + '</a></li>'
                                    }
                                }
                            })
                            htmlQuesLink += '</ul></div></dd></dl></div>';
                            $F.appendTextToDiv("clientResponseDiv", htmlQuesLink);

                            $(".questions a").click(function () {
                                var text = $(this).attr("data");
                                text = $F.wrapURL(text);
                                if ($config.queue.commonQuestionShowType == 0) {
                                    var time = getNowData();
                                    $F.appendTextToDiv("clientResponseDiv", $F.getDisplayMessage("", Constants.agent.id, Constants.agent.name, text, ""));
                                } else {
                                    chatEditor.html(text);
                                    $("#sendBtn_div").click();
                                }
                            })
                        }

                    }
                }
            });
        },

        formatTopNotice: function (msg) {
            return "<div class=\"no-bg no-green\"><div class=\"notice\">" + msg + "</div></div>";
        },
        /**
         * 调用ajax请求
         * @param url
         * @param data
         * @param successFunc
         * @param failFunc
         */
        doAjaxCall: function (url, data, successFunc, failFunc) {
            $.ajax({
                url: url,
                data: data,
                method: 'POST',
                cache: false,
                error: function (jqXHR, textStatus, errorThrow) {
                    $F.log("Ajax error: " + errorThrow + "  xhr status:" + jqXHR.status + " responseText: " + jqXHR.responseText);
                    if ($.isFunction(failFunc)) {
                        failFunc();
                    }
                },
                success: function (response) {
                    if (response == "NOT_LOGGED_IN") {
                        if (!isShowFailTips) {
                            isShowFailTips = true;
                            alert(i18n.common.afkAlert);
                        }
                        clearTimeout(_showRatingTimer);
                        clearTimeout(_titleBlinkTimer);
                        clearTimeout(_pullTimer);
                        if (config && config.page) {
                            location.href = endUrl;
                        }

                    } else {
                        if ($.isFunction(successFunc)) {
                            successFunc(response);
                        }
                    }
                }
            });
        },

        /**
         * 写日志
         * @param content
         * @param server
         */
        log: function (content, server) {
            if (server) {
                $F.doAjaxCall(Constants.ajaxURL, {
                    requestType: 'writeLog',
                    content: content
                });
            }
            console.log(content);
        },

        convertEnterToBr: function (msg) {
            if (!msg)
                return msg;
            msg = msg.replace(/\r\n/ig, "<br/>");
            return msg;
        },

        encodeStringForHtmlEditor: function (str) {
            if (str == null || str == undefined)
                return str;
            else {
                str = str.replace(/\r\n/g, '').replace(/\n\r/g, '').replace(/\r/g, '').replace(/\n/g, '').replace(/\t/g, '').replace(/\b/g, '');
                str = str.replace(/\\/g, '\\\\');
                return str;
            }
        },
        encodeStringByHTMLEscape: function (str) {
            if (str == null || str == undefined)
                return str;
            else {
                //handle encoding key html characters
                str = str.replace(/&/g, '&amp;').replace(/\"/g, '&quot;').replace(/>/g, '&gt;').replace(/</g, '&lt;');//.replace(/ /g, '&nbsp;');
                str = str.replace(/\\/g, '&#92').replace(/\//g, '&#47');
                /*****************************************************
                 Must escape the following carrage returns:

                 \b  Backspace
                 \f    Form feed
                 \n    New line
                 \r    Carriage return
                 \t    Tab
                 ******************************************************/
                str = str.replace(/\r\n/g, '<br/>').replace(/\n\r/g, '<br/>').replace(/\r/g, '<br/>').replace(/\n/g, '<br/>').replace(/\t/g, '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;').replace(/\b/g, '');
                return str;
            }
        },

        /**
         * 去掉字符两端的空白字符
         *
         * @returns string
         */
        trimString: function (sInString) {
            sInString = sInString.replace(/^\s+/g, "");// strip leading
            return sInString.replace(/\s+$/g, "");// strip trailing
        },
        ajaxLoading: function () {
            $("<div class=\"datagrid-mask\"></div>").css({
                display: "block",
                width: "100%",
                height: $(window).height(),
                position: "absolute",
                top: 0,
                left: 0
            }).appendTo("body");
            $("<div class=\"datagrid-mask-msg\"></div>").html(i18n.page.loading).appendTo("body").css({
                display: "block",
                left: ($(document.body).outerWidth(true) - 190) / 2,
                top: ($(window).height() - 45) / 2,
                position: "absolute"
            });
            $(".clearfix").hide();
        },
        ajaxLoadEnd: function () {
            $(".datagrid-mask").remove();
            $(".datagrid-mask-msg").remove();
            $(".clearfix").show();
            $(".c-main-con").scrollTop($("#clientResponseDiv").height());
        }
    };

    function scrollToBottom() {
        $("#talkBox")[0].scrollTop = $("#talkBox")[0].scrollHeight + 30;
    }

    function scrollToNum(num) {
        $("#talkBox").scrollTop(num);
    }


    if (!window.console) {
        window.console = {
            log: function () {
            }
        }
    }

    /**
     * Fix for IE9 : Object doesn't support property or method 'createContextualFragment'
     */
    if ((typeof Range !== "undefined") && !Range.prototype.createContextualFragment) {
        Range.prototype.createContextualFragment = function (html) {
            var frag = document.createDocumentFragment(),
                div = document.createElement("div");
            frag.appendChild(div);
            div.outerHTML = html;
            return frag;
        }
    }

    if (document.all) {
        $("a[href='javascript:;']").on("click", function (e) {
            e.preventDefault();
        });
    }
})(jQuery);